home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_qt3.idb / usr / freeware / Qt / examples / demo / main.cpp.z / main.cpp
Encoding:
C/C++ Source or Header  |  2002-04-08  |  4.5 KB  |  176 lines

  1. /****************************************************************************
  2. ** $Id:  qt/main.cpp   3.0.3   edited Oct 31 22:39 $
  3. **
  4. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  5. **
  6. ** This file is part of an example program for Qt.  This example
  7. ** program may be used, distributed and modified without limitation.
  8. **
  9. *****************************************************************************/
  10.  
  11. #include "frame.h"
  12. #include "graph.h"
  13. #include "display.h"
  14. #include "icons.h"
  15.  
  16. #include "textdrawing/textedit.h"
  17. #include "textdrawing/helpwindow.h"
  18. #include "dnd/dnd.h"
  19. #include "i18n/i18n.h"
  20.  
  21. #include <qmodules.h>
  22.  
  23. #if defined(QT_MODULE_OPENGL)
  24. #include "opengl/glworkspace.h"
  25. #include "opengl/gllandscapeviewer.h"
  26. #endif
  27.  
  28. #if defined(QT_MODULE_CANVAS)
  29. #include "qasteroids/toplevel.h"
  30. #endif
  31.  
  32. #if defined(QT_MODULE_TABLE)
  33. #include "widgets/widgetsbase.h"
  34. #else
  35. #include "widgets/widgetsbase_pro.h"
  36. #endif
  37.  
  38. #include <stdlib.h>
  39.  
  40. #include <qapplication.h>
  41. #include <qimage.h>
  42. #include <qwindowsstyle.h>
  43. #include <qtabwidget.h>
  44. #include <qfont.h>
  45. #include <qworkspace.h>
  46.  
  47. #if defined(QT_MODULE_SQL)
  48. #include <qsqldatabase.h>
  49. #include "sql/book.h"
  50. #include "sql/sqlex.h"
  51. #endif
  52.  
  53. #ifdef Q_OS_MACX
  54. #include <stdlib.h>
  55. #include <qdir.h>
  56. #endif
  57.  
  58. QWidget *Frame::createCategory(const QString &cat)
  59. {
  60.     QTabWidget *tab = 0;
  61.     QWidget *w = 0;
  62.     if(cat == "Widgets") {
  63.     tab = new QTabWidget();
  64.     w = new WidgetsBase( tab );
  65.     tab->addTab( w, "Widget" );
  66.     tab->addTab( new DnDDemo, "Drag and Drop" );
  67. #if defined(QT_MODULE_SQL)
  68.     } else if(cat == "Database") {
  69.     tab = new QTabWidget();
  70.     w = new BookForm( tab );
  71.     tab->addTab( new SqlEx(), "SQL Explorer" );
  72.     tab->addTab( w, "Database" );
  73. #endif
  74. #if defined(QT_MODULE_CANVAS)
  75.     } else if(cat == "2D Graphics") {
  76.     tab = new QTabWidget();
  77.     w = new GraphWidget( tab );
  78.     tab->addTab( w, "Graph Drawing" );
  79.     tab->addTab( new DisplayWidget(), "Display" );
  80. #endif
  81. #if defined(QT_MODULE_OPENGL)
  82.     } else if(cat == "3D Graphics") {
  83.     tab = new QTabWidget();
  84.     w = new GLWorkspace( tab );
  85.     tab->addTab( w, "3d Demo" );
  86.     w = new GLLandscapeViewer( tab );
  87.     tab->addTab( w, "Fractal landscape" );
  88. #endif
  89.     } else if(cat == "Text Drawing/Editing") {
  90.     tab = new QTabWidget();
  91.     TextEdit *te = new TextEdit( tab );
  92.     te->load( "textdrawing/example.html" );
  93.     te->load( "textdrawing/bidi.txt" );
  94.     w = te;
  95.     tab->addTab( w, "Richtext Editor" );
  96.     QString home = QString(getenv("QTDIR")) + "/doc/html/index.html";
  97.     w = new HelpWindow( home, ".", 0, "helpviewer" );
  98.     tab->addTab( w, "Help Browser" );
  99.     } else if(cat == "Internationalization") {
  100.     tab = new QTabWidget();
  101.     w = new I18nDemo(tab);
  102.     tab->addTab(w, "Internationalization");
  103. #if defined(QT_MODULE_CANVAS)
  104.     } else if(cat == "Games") {
  105.     tab = new QTabWidget();
  106.     w = new KAstTopLevel(tab);
  107.     tab->addTab( w, "Asteroids" );
  108. #endif
  109.     } else {
  110.     qDebug("Unknown category: %s", cat.latin1());
  111.     }
  112.     return tab;
  113. }
  114.  
  115.  
  116. int main( int argc, char **argv )
  117. {
  118.     QApplication a( argc, argv );
  119. #ifdef Q_OS_MACX
  120.     setenv("QTDIR", QDir::cleanDirPath(QDir::currentDirPath() + QDir::separator() + ".." + QDir::separator() + ".."), 0);
  121. #endif
  122.  
  123.     Frame::updateTranslators();
  124.  
  125.     // #### how about a splash screen?
  126.     Frame frame;
  127.  
  128.     // example 1
  129.     QPixmap widgetpix( widgeticon );
  130.     QPixmap widgetpix_sel( widgeticon_sel );
  131.     frame.addCategory( NULL, widgetpix, widgetpix_sel, "Widgets" );
  132.  
  133. #if defined(QT_MODULE_SQL)
  134.     // Database
  135.     QPixmap dbpix( dbicon );
  136.     QPixmap dbpix_sel( dbicon_sel );
  137.     frame.addCategory( NULL, dbpix, dbpix_sel, "Database" );
  138. #endif
  139.  
  140. #if defined(QT_MODULE_CANVAS)
  141.     // 2D Graphics
  142.     QPixmap twodpix( twodicon );
  143.     QPixmap twodpix_sel( twodicon_sel );
  144.     frame.addCategory( NULL, twodpix, twodpix_sel, "2D Graphics" );
  145. #endif
  146.  
  147. #if defined(QT_MODULE_OPENGL)
  148.     // 3D Graphics
  149.     QPixmap threedpix( threedicon );
  150.     QPixmap threedpix_sel( threedicon_sel );
  151.     frame.addCategory( NULL, threedpix, threedpix_sel, "3D Graphics" );
  152. #endif
  153.  
  154.     // example 4
  155.     QPixmap textpix( texticon );
  156.     QPixmap textpix_sel( texticon_sel );
  157.     frame.addCategory( NULL, textpix, textpix_sel, "Text Drawing/Editing" );
  158.  
  159.     // example 5
  160.     QPixmap internpix( internicon );
  161.     QPixmap internpix_sel( internicon_sel );
  162.     frame.addCategory( NULL, internpix, internpix_sel, "Internationalization");
  163.  
  164. #if defined(QT_MODULE_CANVAS)
  165.     // example 6
  166.     QPixmap joypix( joyicon );
  167.     QPixmap joypix_sel( joyicon_sel );
  168.     frame.addCategory( NULL, joypix, joypix_sel, "Games" );
  169. #endif
  170.  
  171.     a.setMainWidget( &frame );
  172.     frame.show();
  173.  
  174.     return a.exec();
  175. }
  176.